package com.ayu.shortlink.admin.controller;

import com.ayu.shortlink.admin.common.convention.result.Result;
import com.ayu.shortlink.admin.dto.req.FileUploadReqDTO;
import com.ayu.shortlink.admin.dto.resp.FileUploadRespDTO;
import com.ayu.shortlink.admin.service.FileService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 文件上传控制器
 * TODO ： 1、分片上传 2、断续断传 3、秒传
 */
@RestController
@RequiredArgsConstructor
public class FileController {

    private final FileService fileService;
    /**
     * 上传
     * @return
     */
    @PostMapping("/multipartUpload/init")
    public Result<FileUploadRespDTO> initMultipartUpload(@RequestBody FileUploadReqDTO requestParam){
        return fileService.initMultipartUpload(requestParam);
    }

    /**
     * 根据MD5查找文件
     * @param md5
     * @return
     */
    @GetMapping("/multipartUpload/query/{md5}")
    public Result<FileUploadReqDTO> queryByMD5(@PathVariable String md5){
        return fileService.queryByMD5(md5);
    }

    /**
     * 进行文件合并操作
     * @return
     */
    @PostMapping("/multipartUpload/merge/{md5}")
    public Result<String> mergeMultipartUpload(@PathVariable String md5){
        return fileService.mergeMultipartUpload(md5);
    }
}
